import type { Tab } from '../types';
import ApiConfig from './config'

// 基础URL（已通过vite.config.ts配置代理）
const BASE_URL = '/api/tabs';

// 获取所有标签
export const getAllTabs = async () => {
  return ApiConfig.get<Tab[]>(BASE_URL)
}

export const getTab = async (id: string) => {
  return ApiConfig.get<Tab>(`${BASE_URL}/${id}`)
}

// 创建新标签
export const createTab = async (data: Omit<Tab, 'id'>) => {
  return ApiConfig.post<Omit<Tab, 'id'>, Tab>(BASE_URL, data)
}

export const updateTab = async (id: string, data: Partial<Tab>) => {
  return ApiConfig.put<Partial<Tab>, Tab>(`${BASE_URL}/${id}`, data)
}

// 删除标签
export const deleteTab = async (id: string) => {
  return ApiConfig.delete<void, void>(`${BASE_URL}/${id}`)
}
